In [1]:
from pathlib import Path
from ipyniivue import download_dataset
# GitHub API URL for the base folder
BASE_API_URL = "https://niivue.com/demos/images/"
DATA_FOLDER = Path("images")
# Download data for example
download_dataset(
BASE_API_URL,
DATA_FOLDER,
files=[
"fslmean.nii.gz",
"fslt.nii.gz",
],
)
fslmean.nii.gz already exists. fslt.nii.gz already exists. Dataset downloaded successfully to images.
In [2]:
import ipywidgets as widgets
from IPython.display import display
from ipyniivue import NiiVue, SliceType
# GitHub API URL for the base folder
BASE_API_URL = "https://niivue.com/demos/images/"
# Create niivue instance
# Create a NiiVue instance with specific options
nv = NiiVue(show_3d_crosshair=True)
# Load the volumes
volumes = [
{
"path": DATA_FOLDER / "fslmean.nii.gz",
"colormap": "gray",
"opacity": 1.0,
},
{
"path": DATA_FOLDER / "fslt.nii.gz",
"colormap": "redyell",
"cal_min": 0.05,
"cal_max": 5.05,
"opacity": 0.9,
},
]
nv.load_volumes(volumes)
# Set the slice type to render (3D view)
nv.set_slice_type(SliceType.RENDER)
# Set the clip plane
nv.set_clip_plane(0.15, 270, 0)
# Set the render azimuth and elevation
nv.set_render_azimuth_elevation(45, 45)
# Create interactive checkbox
# Create a checkbox to toggle background masks overlays
background_masks_checkbox = widgets.Checkbox(
value=False,
description="Background masks overlay",
disabled=False,
)
# Function to handle checkbox changes
def on_background_masks_change(change):
"""Set background mask overlay."""
nv.background_masks_overlays = change.new
# Observe changes to the checkbox
background_masks_checkbox.observe(on_background_masks_change, names="value")
# Display all
display(background_masks_checkbox)
display(nv)